package com.curd.demo.config;

import com.curd.demo.config.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())//不能在里面直接new，它到不了容器里面
                .addPathPatterns("/**")// 拦截所有请求，通过判断token是否合法来 决定是否需要登录
                .excludePathPatterns("/user/login","/user/register","/**/export","/**/import","/file/**");
        //                              登录          注册                导出        导入
    }

    @Bean//要在这里定义并注入容器
    public JwtInterceptor jwtInterceptor(){
        return new JwtInterceptor();
    }
}
